cd code

########## CONSUMER ADOPTIONS: make runData and estimate model ##########
cd consumerAdoptions
# Estimate model versions
execMatlab "for runid = [1 101:106 201:206]; makeRunData_consumerAdoptions(runid); estimation_consumerAdoptions(runid); end;  quit();"
# Compute elasticities
execMatlab "computeElasticities_consumerAdoptions(201);  quit();"
execMatlab "computeMultiplyingFactors_consumerAdoptions(201);  quit();"
# Simulate addition of one extra provider to understand the spatial nature of network effects
execMatlab "simulateOneExtraProvider(201); quit();"
cd ..

########## PROVIDER ADOPTIONS: make runData and estimate model ##########
cd providerAdoptions
# Estimate model versions
execMatlab "for runid = [1 101:102 201:202]; makeRunData_providerAdoptions(runid); estimation_providerAdoptions(runid);  end; quit();"
# Compute elasticities
execMatlab "computeElasticities_providerAdoptions(201);  quit();"
execMatlab "computeMultiplyingFactors_providerAdoptions(201);  quit();"
cd ..

########## PROVIDER EXITS: make runData and estimate model ##########
cd providerExits
# Estimate models
execMatlab "for runid = [1 101:102 201:202]; makeRunData_providerExits(runid); estimation_providerExits(runid);  end; quit();"
# Compute elasticities
execMatlab "computeElasticities_providerExits(201);  quit();"
execMatlab "computeMultiplyingFactors_providerExits(201);  quit();"
cd ..


########## SIMULTANEOUS ADOPTION BY CONSUMER AND PROVIDER (symmetric definition of adoption) ##########
cd pairAdoptions
execMatlab "makeRunData_pairAdoptions(201);makeRunData_pairAdoptions(101);estimation_pairAdoptions(101); estimation_pairAdoptions(201); quit();"
execMatlab "displayEstimates(201); quit();"
cd ..

########## ALTERNATIVE DEFINITION OF ADOPTION BASED ON ACCOUNT CREATION (separate for each "type") ##########
cd acctCreation
execMatlab "for runid = [1:3]; makeRunData_acctCreation_ctsTime(runid); estimation_acctCreation(runid); end; quit();"
execMatlab "displayEstimates_acctCreation([1:3]); quit();"
cd ..



########## FULL MODEL: run (joint) dynamic predictions (base case) + counterfactuals ##########
cd jointProcess

execMatlab "displayEstimates(201); quit();"

execMatlab "displayEstimates(101); quit();"
execMatlab "displayEstimates(1); quit();"

execMatlab "displayEstimates(206); quit();"

execMatlab "displayEstimates(202); quit();"
execMatlab "displayEstimates(203); quit();"
execMatlab "displayEstimates(204); quit();"
execMatlab "displayEstimates(205); quit();"

# Compare results between continuous-time and discrete-time (daily and weekly) versions
execMatlab "runCompareResults([201 101 1], '../../results/continuous_time/jointProcess/run_201/robustCheckDiscrete'); quit();"

# Provide exhibits for distribution of outcome variables (Y per discrete period / spell durations / distance k-k' across transactions)
execMatlab "runSummarizeOutcomeVariable(201); quit();"

# Run dynamic predictions (base case)
execMatlab "runDynamicPrediction(201);      quit();"
execMatlab "runPlotDynamicPredictions(201); quit();"

# Run counterfactuals
execMatlab "for cnfactType = [1:6];  disp(cnfactType); runCounterfactuals(201,cnfactType); end; quit();"

# Postprocess results of counterfactuals
execMatlab "runCombineCounterfactuals(201, [1 2], 'seeding_by_type'); quit();"
execMatlab "runCombineCounterfactuals(201, [3:5], 'seeding_providers_by_location', false); quit();"
execMatlab "run runPlotAdvertisingEffect.m; quit();" # Prepare inputs to make chart on advertising effect (see Excel file)


########## PARAMETER RECOVERY TASKS ##########
### Launch a parameter recovery task based on data generated dynamically (with discrete time and / or continuous time)
# Generate data according to continuous time model; timestamps are stored for all events + another version is stored that aggregates adoptions per day
execMatlab "runParamRecovery_generate(201, 10); quit();"

# Estimate continuous-time model
execMatlab "for iter = 1:10; for Yidx = 1:3; runParamRecovery_estimate(201, 2, iter, Yidx); end; end; quit();"
# Get the results in a txt table for copy-paste in latex
execMatlab "runParamRecovery_displayResults(201, 2, [1:10]); quit();"

# Estimate day-level model based on data aggregated at day level
execMatlab "for iter = 1:10; for Yidx = 1:3; runParamRecovery_estimate(201, 1, iter, Yidx); end; end; quit();"
# Get the results in a txt table for copy-paste in latex
execMatlab "runParamRecovery_displayResults(201, 1, [1:10]); quit();"

cd ..

cd ..
